const doctor = require("../service/doctor");

// 获取医生
const getdoctorlist = async (ctx) => {
    let res = await doctor.Getdoctorlist(ctx.query)
    if (res.length > 0) {
        return ctx.body = {
            code: 200,
            message: "获取成功",
            data: res,
        }
    } else {
        return ctx.body = {
            code: 400,
            message: "暂无数据,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600",
        }
    }
}

// 获取医生所属的大科室
const getadmin = async (ctx) => {
    let res = await doctor.Getadmin(ctx.query)
    if (res.length > 0) {
        return ctx.body = {
            code: 200,
            message: "获取成功",
            data: res,
        }
    } else {
        return ctx.body = {
            code: 400,
            message: "暂无数据,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600",
        }
    }
}

// 获取医生所属的大科室下的小科室
const getadminchildred = async (ctx) => {
    let res = await doctor.Getadminchildred(ctx.query)
    if (res.length > 0) {
        return ctx.body = {
            code: 200,
            message: "获取成功",
            data: res,
        }
    } else {
        return ctx.body = {
            code: 400,
            message: "暂无数据,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600",
        }
    }
}

// 获取医生的职位
const getposition = async (ctx) => {
    let res = await doctor.Getposition(ctx.query)
    if (res.length > 0) {
        return ctx.body = {
            code: 200,
            message: "获取成功",
            data: res,
        }
    } else {
        return ctx.body = {
            code: 400,
            message: "暂无数据,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600",
        }
    }
}

// 添加医生
const Adddoctorlist = async (ctx) => {
    let res = await doctor.Adddoctorlist(ctx.request.body)
    if (res.affectedRows > 0) {
        let reds = await doctor.Addadminchildrenstaff(ctx.request.body)
        if (reds.affectedRows > 0) {
            return ctx.body = {
                code: 200,
                message: "操作成功"
            }
        }
        return ctx.body = {
            code: 200,
            message: "操作成功"
        }
    } else {
        return ctx.body = {
            code: 400,
            message: "添加失败,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600"
        }
    }
}

// 删除医生
const Deldoctorlist = async (ctx) => {
    let res = await doctor.Deldoctorlist(ctx.query)
    if (res.affectedRows > 0) {
        let reds = await doctor.Reduceadminchildrenstaff(ctx.request.body)
        if (reds.affectedRows > 0) {
            return ctx.body = {
                code: 200,
                message: "操作成功"
            }
        }
        return ctx.body = {
            code: 200,
            message: "删除成功"
        }
    } else {
        return ctx.body = {
            code: 400,
            message: "删除失败,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600"
        }
    }
}

// 修改医生
const Updateddoctorlist = async (ctx) => {
    let res = await doctor.Updateddoctorlist(ctx.request.body)
    if (res.affectedRows > 0) {
        return ctx.body = {
            code: 200,
            message: "修改成功"
        }
    } else {
        return ctx.body = {
            code: 400,
            message: "修改失败,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600"
        }
    }
}

module.exports = {
    getdoctorlist,// 获取医生的数据
    getadmin,// 获取医生所属的科室
    getadminchildred,// 获取医生所属的科室的子科室
    getposition,// 获取医生所属的职位
    Adddoctorlist, // 添加医生的数据
    Updateddoctorlist,// 修改医生的数据
    Deldoctorlist,// 删除医生的数据
}